<?php
// +----------------------------------------------------------------------
// | PHP [ JUST YOU ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2017 http://www.jyphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: FlyingPig <flyingpigfp@163.com>
// +----------------------------------------------------------------------

namespace App\Common;
use Illuminate\Support\Facades\DB;


class Sql
{
    /**
     * 此静态查询方法兼容以前的SQL查询数据结构
     * @param string $table
     * @param array $where
     * @param null $column
     * @return array
     */
    public static function select($table = '',$where = [],$column = null)
    {
        $db = DB::table($table);
        if ($where) {
            $db->where($where);
        }
        return $db->get($column)->map(function ($value){
            return (array)$value;
        })->toArray();
    }


    /**
     * update
     * @param string $table
     * @param array $where
     * @param array $update
     * @return int
     */
    public static function update($table = '',$where = [],$update = [])
    {
        return DB::table($table)->where($where)->update($update);
    }


    /**
     * insert
     * @param string $table
     * @param array $data
     * @return int
     */
    public static function insert($table = '',$data = [])
    {
        return DB::table($table)->insertGetId($data);
    }

}